﻿var timerHelper = (function () {

	  
	 

	var _count = 0;
	var onTimeEvent;
	var onTimeRuningEvent;

	var _hhDom, _mmDom, _ssDom;


	var setOnTimeEnd = function (func) {
		if (func)
			onTimeEvent = func;
	}
	var onTimeRuning;
	var setOnTimeRuning = function (hh, mm, ss) {
		_hhDom = hh;
		_mmDom = mm;
		_ssDom = ss;
	}

	var show = function (h,m,s) {
		 
		$(_hhDom).html(h);
		$(_mmDom).html(m);
		$(_ssDom).html(s);
	}

	var start = function (m) {
		var maxtime = m;
		var minutes = 0;
		var seconds = 0;
		timer = setInterval(function () {

			if (maxtime >= 0) {
				minutes = Math.floor(maxtime / 60);
				seconds = Math.floor(maxtime % 60);
				  
				 
				--maxtime;
			} else {
				clearInterval(timer);
				onTimeEvent();
			}
			show(0, minutes, seconds);
		}, 1000); 

		
	};


	return {
		start: start,
		setOnTimeEnd: setOnTimeEnd,
		setOnTimeRuning: setOnTimeRuning 
		 

	};

　　})();